{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3077e4e0-d1d9-470b-b28a-b18896e27bd6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入年份（>=1），否则为1： 2004\n",
      "请输入月份（1~12），否则<1为1、>12为12： 32\n",
      "请输入日期（1~31），否则<1为1、>ndays(y,m)为ndays(y,m)： 23\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2004 年 12 月 23 日是 星期四\n"
     ]
    }
   ],
   "source": [
    "from calendar import *\n",
    "def ndays(y,m):\n",
    "    #每个月的正常天数\n",
    "    monthDay=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "    days = monthDay[ m-1]\n",
    "    if (m==2 and isleap(y)):\n",
    "        days+=1\n",
    "    return(days)\n",
    "def fromdays(y,m,d):\n",
    "    days = 0\n",
    "    for i in range(1,y):\n",
    "        days += 365\n",
    "        if(isleap(i)): days+=1\n",
    "    for i in range(1,m):\n",
    "        days += ndays(y,i)\n",
    "    days+=d\n",
    "    return(days)\n",
    "#Python注释代码1 #Python注释代码2\n",
    "#测试代码\n",
    "y=int(input(\"请输入年份（>=1），否则为1：\"))\n",
    "m=int(input(\"请输入月份（1~12），否则<1为1、>12为12：\"))\n",
    "d=int(input(\"请输入日期（1~31），否则<1为1、>ndays(y,m)为ndays(y,m)：\"))\n",
    "if y<1: y=1\n",
    "if m<1: m=1\n",
    "if m>12: m=12\n",
    "if d<1: d=1\n",
    "if d>ndays(y,m): d=ndays(y,m)\n",
    "w={0:'星期日',1:'星期一', 2:'星期二',3:'星期三', 4:'星期四',5:'星期五', 6:'星期六'}\n",
    "print(y,\"年\",m,\"月\",d,\"日是\",w[fromdays(y,m,d) % 7])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5a39c31-62dd-44df-8226-9e707e4587ec",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
